import 'package:backend.core/core/domain/entities/api/web/api_web_one_time_purchased_item_transaction.dart';
import 'package:backend.core/core/domain/entities/api/web/api_web_purchased_subscription_transaction.dart';
import 'package:backend.core/core/domain/entities/api/web/api_web_transaction.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_one_time_purchased_item_transaction_dto_factory.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_purchased_subscription_transaction_dto_factory.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_transaction_dto.dart';

class ApiWebTransactionDtoFactory {
  const ApiWebTransactionDtoFactory._internal();

  static const _instance = ApiWebTransactionDtoFactory._internal();

  factory ApiWebTransactionDtoFactory() {
    return _instance;
  }

  ApiWebTransactionDto fromEntity(ApiWebTransaction transaction) {
    if (transaction is ApiWebOneTimePurchasedItemTransaction) {
      return ApiWebOneTimePurchasedItemTransactionDtoFactory().fromEntity(transaction);
    }

    if (transaction is ApiWebPurchasedSubscriptionTransaction) {
      return ApiWebPurchasedSubscriptionTransactionDtoFactory().fromEntity(transaction);
    }

    throw UnimplementedError();
  }
}
